<template>
	<view>
		<!-- <view class="height" style="height: 120rpx;background-color: #fff;">
			
		</view> -->
		<view class="" v-if="webinfo.roles==5">
			<homeAssociaton :webinfo="webinfo"></homeAssociaton>
		</view>
		<view   class="" v-if="webinfo.roles==2">
			<homeTourist
			:webinfo="webinfo"
			></homeTourist>
		</view>
	</view>
</template>

<script>
	import homeTourist from '@/components/home_tourist.vue'
	import homeAssociaton from '@/components/home_association.vue'
	import { mapState, mapMutations } from 'vuex'
	export default {
		components:{
			homeTourist,
			homeAssociaton
		},
		data() {
			return {
				auther:null,
				webinfo:{},
				memberId:'',
				storeId:'',
				shopId:'',
				starttime:'',
				endtime:'',
				timelong:'',
				searchId:'',//搜索店铺id
			};
		},
		onShareAppMessage:function(){
			// console.log(this.userCenterData.memberId,'11');
			let pathinfo=''
			let limag=this.webinfo.bannerList[0].websiteImage?this.webinfo.bannerList[0].websiteImage:this.webinfo.bannerList[0].websiteSellerImage
			if(this.userCenterData.vendorId && this.userCenterData.storeId){
				 pathinfo=`/webcont/webindex/webindex?memberId=${this.userCenterData.memberId}&storeId=${this.userCenterData.vendorId}&shopId=${this.userCenterData.storeId}`
			}else{
				 pathinfo=`/webcont/webindex/webindex?&memberId=${this.userCenterData.memberId}`
			}
			// let pathinfo='/extra/activityList/activityList'
			return{
				title: this.webinfo.storeName,
				path:pathinfo,
				imageUrl: limag,
			}
			
		},
		onShareTimeline: function() {
			let limag=this.webinfo.bannerList[0].websiteImage?this.webinfo.bannerList[0].websiteImage:this.webinfo.bannerList[0].websiteSellerImage
			let pathinfo=''
			if(this.userCenterData.vendorId){
				 pathinfo=`/webcont/webindex/webindex?memberId=${this.userCenterData.memberId}&storeId=${this.userCenterData.vendorId}&shopId=${this.userCenterData.storeId}`
			}else{
				  pathinfo=`/webcont/webindex/webindex?&memberId=${this.userCenterData.memberId}`
			}
			return {
				title: this.webinfo.storeName,
				path:pathinfo,
				imageUrl: limag,
			}
		},
		computed: {
		  ...mapState(['hasLogin', 'userInfo', 'userCenterData'])
		},
		onLoad(options) {
			if(this.$Route.query.searchId){
				console.log(this.$Route.query.searchId);
				this.searchId=this.$Route.query.searchId
					uni.setStorageSync('storeId', this.searchId);
			}
			this.starttime=new Date().getTime()
			// this.getuser()
			this.memberId=this.$Route.query.memberId
			this.storeId=this.$Route.query.storeId
			this.shopId=this.$Route.query.shopId
			if(!this.$Route.query.searchId && !this.$Route.query.storeId){
				uni.setStorageSync('storeId', this.userCenterData.vendorId)
				console.log('okok');
			}
			// 商户id
			if(this.storeId){
						uni.setStorageSync('storeId', this.storeId);
					}
					// 店铺
			if(this.shopId){
						uni.setStorageSync('shopId', this.shopId);
					}
			// 保存推荐人id
			if(this.memberId){
				uni.setStorageSync('referrerId', this.memberId);
			}
			this.getwebinfo()
		},
		onShow() {
			if(!this.$Route.query.searchId && !this.$Route.query.storeId){
				uni.setStorageSync('storeId', this.userCenterData.vendorId)
				// console.log('okok');
				this.getwebinfo()
			}else{
				this.getwebinfo()
			}
		},
		onHide() {
			
				this.endtime=new Date().getTime()
				this.timelong=this.endtime-this.starttime
				if(this.hasLogin){
					 this.addcustomer()
				}
				
				
				},
		methods:{
			// 获取用户身份		 // 获取用户身份1、会员, 2、商户，3、平台  4、散户 5、协会
			// getuser(){
			// 	this.$request({
			// 		url:'v3/seller/front/vendor/roles',
			// 		method:"GET",
			// 		data:{vendorMobile:this.userCenterData.memberMobile}
			// 	}).then(res=>{
					
			// 		if(res.state==200){
			// 			this.auther=res.msg
			// 			this.getwebinfo()
						
			// 		}else{
			// 			this.auther=4
			// 			this.getwebinfo()
			// 		}
					
			// 	})
			// },
			timechange(time){
			 	 //时间戳为10位需*1000，时间戳为13位的话不需乘1000
			 	  var date = new Date(time);
			 	  var Y = date.getFullYear() + '-';
			 	  var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth()+1) : date.getMonth() + 1) + '-';
			 	  var D = (date.getDate() < 10 ? '0'+date.getDate() : date.getDate()) + ' ';
			 	  var h = (date.getHours() < 10 ? '0'+date.getHours() : date.getHours()) + ':';
			 	  var m = (date.getMinutes() < 10 ? '0'+date.getMinutes() : date.getMinutes())+ ':';
			 	  var s = (date.getSeconds() < 10 ? '0'+date.getSeconds() : date.getSeconds());
			 	  return  Y + M + D + h + m + s;
			 },
			// 添加
			addcustomer(){
				
			let pnone=uni.getDeviceInfo()
				
				let param={}
				
				param.data=
				{
					address:uni.getStorageSync('address'),//地址
					avatar:this.userCenterData.memberAvatar,//头像
					birthday:'2023-11-09',//生日
					browGoods:this.webinfo.storeName,//活动名称
					browGoodsId:this.storeId,//商品id
					browTime:(this.timelong/1000).toFixed(1),
					company:'',//公司
					createBy:this.userCenterData.memberName,
					createTime:this.timechange(new Date()),
					cusCustomerIntention:'3',//客户意向方（0-高意向，1-中意向，2-低意向 3-无意向）
					cusDealOrNot:'1',//(0-已成交，1-未成交)
					// cusFollowStage:'0',//跟进阶段(0-初步沟通，1-确定意向，2-等待付款)
					customerDescription:'',//	客户描述
					customerName:this.userCenterData.memberName,//客户姓名
					email:this.userCenterData.memberEmail,//邮箱
					jobTitle:'',//职务名称
					phoneAddress:uni.getStorageSync('address'),//手机号地址
					phoneNum:this.userCenterData.memberMobile,//手机号
					referrerId:this.memberId,
					referrerUsername:'',
					scoreUsername:'微官网',//渠道
					sex:this.storeId,//性别
					source:'0',//来源
					wechatId:'',//微信号
					wechatName:'',//微信昵称
					temporaryId:pnone.deviceId,
					// customerTaskId:this.$Route.query.taskId,
					// customerIndexId:this.$Route.query.indexId,
				}
				
				param.url='v3/customer/front/appCustomer'
				param.method="POST"
				param.header={
				  'Content-Type': 'application/json'
				}
				// param.data=JSON.stringify(param.data)
				console.log(param);
				this.$request(param)
				
			},
			// 获取微官网数据
			getwebinfo(){
				if(this.searchId){
					uni.setStorageSync('storeId', this.searchId)
					 
					this.$request({
						url:'v3/website/front/member/all/list',
						method:'GET',
						data:{vendorId:this.searchId}
					}).then(res=>{
						this.webinfo=res.data
						// this.webinfo.type=1
					})
				}else{
					if(uni.getStorageSync('storeId')){
						
						this.$request({
							url:'v3/website/front/member/all/list',
							method:'GET',
							data:{vendorId:uni.getStorageSync('storeId')}
						}).then(res=>{
							this.webinfo=res.data
							// this.webinfo.type=1
						})
					}else{
						uni.showToast({
							title:"未获取到商户信息",
							icon:'none'
						})
						uni.navigateBack({delta:1})
					}
				}
				
				// 判断
				// if(this.auther=='4'||!this.hasLogin){
				// 	// 散户
				// 	if(uni.getStorageSync('storeId')){
				// 		this.$request({
				// 			url:'v3/website/front/member/all/list',
				// 			method:'GET',
				// 			data:{vendorId:uni.getStorageSync('storeId')}
				// 		}).then(res=>{
				// 			this.webinfo=res.data
				// 			this.webinfo.type=1
				// 		})
				// 	}else{
				// 		uni.showToast({
				// 			title:"未获取到商户信息",
				// 			icon:'none'
				// 		})
				// 		uni.navigateBack({delta:1})
				// 	}
				// }else{
				// 		console.log('feidenglu');
				// 	// 非散户
				// 	this.$request({
				// 		url:'v3/website/front/member/all/list',
				// 		method:'GET',
				// 		data:{vendorId:this.userCenterData.vendorId}
				// 	}).then(res=>{
				// 		this.webinfo=res.data
				// 		this.webinfo.type=1
				// 	})
				// }
				
			}
		}
	}
</script>

<style lang="scss">

</style>
